package com.art.utils;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

/**
 * IntelliJ IDEA
 *
 * @author 谭礼赞 2038940123
 * @since 2022-11-07-2022/11/7
 */

public class MybatisUtil {
    private static SqlSessionFactory factory;
    static{
        try {
            factory=new SqlSessionFactoryBuilder ().build ( Resources.getResourceAsReader ("mybatis-config.xml"));
        } catch (IOException e) {
            e.printStackTrace ();
        }
    }

    public static SqlSession getSqlSession() {
        return factory.openSession (true);
    }
}
